<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up()
    {
        Schema::create('wechat_service_account_users', function (Blueprint $table) {
            // 主键ID
            $table->id();
            $table->string('openid')->unique()->comment('微信用户唯一标识');
            $table->string('session_key')->comment('微信会话密钥');
            $table->timestamp('session_expires_at')->nullable()->comment('会话过期时间');
            $table->string('nickname')->nullable()->comment('用户昵称');
            $table->string('avatar')->nullable()->comment('用户头像URL');
            $table->tinyInteger('gender')->nullable()->comment('用户性别：0未知，1男，2女');
            $table->string('country')->nullable()->comment('用户所在国家');
            $table->string('province')->nullable()->comment('用户所在省份');
            $table->string('city')->nullable()->comment('用户所在城市');
            $table->string('phone')->nullable()->unique()->comment('用户手机号');
            $table->text('access_token')->nullable()->comment('加密后的access_token');
            $table->timestamp('access_token_expires_at')->nullable()->comment('access_token过期时间');
            $table->timestamps();
        });
    }

    public function down()
    {
        Schema::dropIfExists('wechat_service_account_users');
    }
};